#pragma comment(lib,"corona")
#include "Game.h"
#include "../Util/corona.h"


extern tActionMapping kaActionMapping[];

//Initializate game
bool cGame::Init()
{
  //Init managers
  cInputManager::Get().Init(kaActionMapping, eIA_Count);
  cGraphicManager::Get().Init();

  //Load resources and init level
  LoadResources();
 
  mbFinished = false;

  return true;
}

//Update game status
void cGame::Update( float lfTimeStep )
{
  //Update the input manager
  cInputManager::Get().Update(lfTimeStep);
  cLevel::Get().Update(lfTimeStep);

  //Check the exit condition
  if (IsPressed(eIA_CloseApplication) )
  {
    mbFinished = true;
    return;
  }
}

//Render actual frame
void cGame::Render()
{
  //Get the graphic manager
  cGraphicManager &lGraphic = cGraphicManager::Get();
  
  //Initialize current frame
  lGraphic.InitFrame();
  //Render level
  cLevel::Get().Render();

  //SwapBuffers
	lGraphic.SwapBuffers();
}

//Load Resources
void cGame::LoadResources()
{
  cLevel::Get().Init("./Data/Level.xml");
}

//Deinitializate game
bool cGame::Deinit()
{
  cGraphicManager::Get().Deinit();
  cInputManager::Get().Deinit();
  cLevel::Get().Deinit();
  return true;
}

